/**
 * @param {number} x
 * @return {number}
 */
export var mySqrt = function (x) {
  let left = 0,
    right = x
  let ans = 1
  while (left <= right) {
    const mid = left + Math.floor((right - left) / 2)
    const square = mid * mid
    if (square === x) return mid
    if (square < x) {
      ans = mid
      left = mid + 1
    } else right = mid - 1
  }
  return ans
}
